<template>
  <div>
    <el-form
      ref="editForm"
      :model="editForm"
      class="pd20"
      label-width="120px"
      label-position="right"
      size="medium"
    >
      <el-form-item label="兑换商品等级:">
        <goods-rank-list
          :rank-id="editForm.rankId"
          @change="goodsRankChange"
        />
      </el-form-item>
      <el-form-item label="券码数量:">
        <el-input-number
          v-model="editForm.num"
          autocomplete="off"
          placeholder="请输入"
        />
      </el-form-item>
      <el-form-item label="是否启用:">
        <el-radio v-model="editForm.isEnable" label="true">启用</el-radio>
        <el-radio v-model="editForm.isEnable" label="false">禁用</el-radio>
      </el-form-item>
      <el-form-item label="生效时间:">
        <el-date-picker
          v-model="editForm.effectiveTime"
          type="datetime"
          placeholder="选择日期时间"
          format="yyyy-MM-dd HH:mm:ss"
          value-format="yyyy-MM-dd HH:mm:ss"
        />
      </el-form-item>
      <el-form-item label="过期时间:">
        <el-date-picker
          v-model="editForm.expirationTime"
          type="datetime"
          placeholder="选择日期时间"
          format="yyyy-MM-dd HH:mm:ss"
          value-format="yyyy-MM-dd HH:mm:ss"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm">提交</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>

import { addCoupon } from '@/api/coupon'

const editForm = {
  rankId: 0,
  num: 10,
  isEnable: false,
  effectiveTime: '',
  expirationTime: ''
}
export default {
  components: {},
  props: {
    selectOrder: {
      type: Array,
      default: function() {
        return []
      }
    },
    goodsId: {
      type: Number,
      default: 0
    },
    goodsRankName: {
      type: String,
      default: 'A'
    }
  },
  data() {
    return {
      editForm,
      // 上传
      uploadHeaders: {
        Authorization: `Bearer ${JSON.parse(localStorage.info).access_token}`,
        timeout: 50000
      }

    }
  },
  created() {},
  methods: {
    // 发布
    async submitForm() {
      const params = this.editForm
      await addCoupon(params)
      this.$message.success('新增商品成功')
      this.$emit('onCouponsAdd')
    },
    handleSuccess(res, type) {
      this.editForm[type].push(res.data.enclosure)
    },
    /**
     * 等级变化
     */
    goodsRankChange(id, row) {
      this.editForm.rankId = id
      this.editForm.goodsRankName = row.rank
    },
    showSuccessMsg() {
      this.$message({
        message: '上传成功',
        type: 'success'
      })
    },
    showFailMsg() {
      this.$message.error('上传失败')
    }
  }
}
</script>
